package zuoye726;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Demo4 {
	public static void main(String[] args) throws Exception {
		File src=new File("D:\\012javacopy");
		File dest=new File("Testjava\\");
		
	
		try{
			copy(src,dest);
		}catch(FileNotFoundException e){
			e.printStackTrace();
		}
		
	}

	private static void copy(File src,File dest) throws Exception {
		File[] listFiles = src.listFiles();
		
		if(src.isDirectory()){
			if (!dest.exists()) {  
	            dest.mkdirs(); 
	        } 	
		
		if(listFiles!=null){
			for(File file:listFiles){
				File newFile=new File(dest,file.getName());
				copy(file,newFile);
				
			}
		}
		}else{	FileInputStream srcfile=new FileInputStream(src);
		      FileOutputStream destfile=new FileOutputStream(dest);
				byte[] b=new byte[1024];
				int len=0;
				while((len=srcfile.read(b))!=-1){
					destfile.write(b, 0, len);
				}
			srcfile.close();
			destfile.close();
		}
		
		
		
}
}
	
		
	


